package com.example.project.service.impl;

import com.example.project.model.FAQ;
import com.example.project.model.Feedback;
import com.example.project.repository.FAQRepository;
import com.example.project.repository.FeedbackRepository;
import com.example.project.repository.UserRepository;
import com.example.project.service.FeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.security.Timestamp;
import java.util.List;
import java.util.Optional;

@Service
public class FeedbackServiceImpl implements FeedbackService {

    @Autowired
    private FeedbackRepository feedbackRepository;

    @Autowired
    private UserRepository userRepository;

    @Override
    public List<Feedback> getAllFeedbacks() {
        return feedbackRepository.findAll();
    }

    @Override
    public boolean addFeedback(Feedback feedback) {
        // 检查用户是否存在
        if (userRepository.existsById(feedback.getUser().getId())) {
            feedbackRepository.save(feedback);
            return true;
        }
        return false;
    }

    @Override
    public boolean deleteFeedback(int id) {
        if (feedbackRepository.existsById(id)) {
            feedbackRepository.deleteById(id);
            return true;
        }
        return false;
    }

    @Override
    public Feedback getFeedbackById(int id) {
        return feedbackRepository.findById(id).orElse(null);
    }
}